#include "gtest/gtest.h"
#include <mockcpp/mokc.h>
#include <mockcpp/mockcpp.hpp>
 
#include <vector>
#include <tuple>
#include <iostream>
 
#include "topoinfo_struct.h"
#include "log.h"
#include "checker.h"
#include "virtual_topo.h"
#include "testcase_utils.h"
#include "coll_native_executor_base.h"
 
using namespace hccl;

class ReduceScatterGeneralizationTypeTest: public ::testing::TestWithParam<std::tuple<HcclReduceOp>> {

public:
    static void SetUpTestCase()
    {
        std::cout << "ReduceScatterGeneralizationTypeTest set up." << std::endl;
    }

    static void TearDownTestCase()
    {
        std::cout << "ReduceScatterGeneralizationTypeTest tear down." << std::endl;
    }

    virtual void SetUp()
    {
        const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
        std::string caseName = "analysis_result_" + std::string(test_info->test_case_name()) + "_" + std::string(test_info->name());
        Checker::SetDumpFileName(caseName);
    }

    virtual void TearDown()
    {
        Checker::SetDumpFileName("analysis_result");
        GlobalMockObject::verify();
        // 这边每个case执行完成需要清理所有的环境变量，如果有新增的环境变量，需要在这个函数中进行清理
        ClearHcclEnv();
    }

};

TEST_P(ReduceScatterGeneralizationTypeTest, ReduceScatter_test)
{
    const auto& mytuple = GetParam();

    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 1);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = std::get<0>(mytuple);

    testOpParam.algName = "ReduceScatterMeshOpbasePipelineExecutor";
    Checker checker;
    HcclResult ret;

    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

INSTANTIATE_TEST_CASE_P(ReduceScatterCaseTestType, ReduceScatterGeneralizationTypeTest,
        testing::Values(HcclReduceOp::HCCL_REDUCE_SUM, HcclReduceOp::HCCL_REDUCE_PROD, HcclReduceOp::HCCL_REDUCE_MAX, HcclReduceOp::HCCL_REDUCE_MIN)
);
